package com.zb.sms.controller;

import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.zb.exception.SMSException;
import com.zb.result.Result;
import com.zb.util.MobileUserSmsUtil;
import com.zb.utils.VerificUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author WEN
 * @Date 2023/7/10 0010
 **/
@Api(tags = "短信类客户报单端接口")
@RestController
@RequestMapping("/mobile/sms/user")
public class SMSUserController {
    @ApiOperation("注册类验证码")
    @GetMapping("/registerCode")
    public Result registerCode(@ApiParam(value = "手机号", required = true) String phone) throws SMSException {
        Assert.isTrue(VerificUtil.phoneVerific(phone), "请输入正确的手机号格式！", phone);
        MobileUserSmsUtil.sendRegisterVerificCode(phone);
        return Result.success("验证码发送成功！");
    }

    @ApiOperation("登录类验证码")
    @GetMapping("/loginCode")
    public Result loginCode(@ApiParam(value = "手机号", required = true) String phone) throws SMSException {
        Assert.isTrue(VerificUtil.phoneVerific(phone), "请输入正确的手机号格式！", phone);
        MobileUserSmsUtil.sendLoginVerificCode(phone);
        return Result.success("验证码发送成功！");
    }

    @ApiOperation("更改类验证码")
    @GetMapping("/updateCode")
    public Result updateCode(@ApiParam(value = "手机号", required = true) String phone) throws SMSException {
        Assert.isTrue(VerificUtil.phoneVerific(phone), "请输入正确的手机号格式！", phone);
        MobileUserSmsUtil.sendUpdateVerificCode(phone);
        return Result.success("验证码发送成功！");
    }

    @ApiOperation("查询类的验证码")
    @GetMapping("/selectCode")
    public Result selectCode(@ApiParam(value = "手机号", required = true) String phone) throws SMSException {
        Assert.isTrue(VerificUtil.phoneVerific(phone), "请输入正确的手机号格式！", phone);
        MobileUserSmsUtil.selectCode(phone);
        return Result.success("验证码发送成功！");
    }
}
